/*
 * @Author: Wang Junwen wangjunwendut@163.com
 * @Date: 2024-10-25 13:51:14
 * @LastEditors: yuanchenxi 836909158@qq.com
 * @LastEditTime: 2025-03-04 19:36:24
 * @FilePath: \SGFEM\Solver\Task\Common\test\ConcentrationForceCalculatorTest.hpp
 * @Description: 
 * 
 * Copyright (c) 2024 by 神工仿真, All Rights Reserved. 
 */

#pragma once
#include "gtest/gtest.h"
// #include "DBManager/IService/Input/Node/INodeService.h"
#include "TestData/model/CORD_Model.hpp"
#include "TestData/model/OnePyram5Ele.hpp"
#include "TestData/model/Cube_OneHexa8Ele.hpp"
#include "TestData/model/Cube_OneHexa8EleWarpFace.hpp"
#include "DataStructure/Common/Constant.h"

#include "../LoadCalculator.h"

class ForceInLocalCoordTest : public ::testing::Test
{
public:
    static void SetUpTestSuite ()
    {
        // Input
        CORD_Model model;
        dbManager = model.GetModel();

        // 初始化排序，计算坐标系基矢量
        auto& assembly = AssemblyEigen::GetInstance();
        assembly.Clear();
        
        auto para = dbManager->get<ISubcaseService> () ->FindSubCase (1);
        SG::DataStructure::FEM::Subcase subcase(para);
        assembly.Initialize (dbManager, subcase, {1});

        auto& coordHandler = CoordinateProcessor::GetInstance();
        coordHandler.Initialize (dbManager);
    }
protected:
    static DBServiceFactorySP dbManager;
};

DBServiceFactorySP ForceInLocalCoordTest::dbManager;

TEST_F (ForceInLocalCoordTest, ForceCORD1CTest)
{
    //输入力的信息
    SG::DataStructure::FEM::FORCEData force;
    force.m_sId         = 1;
    force.m_coordSysmId = 100;
    force.m_nodeId      = 10;
    force.m_load[0]     = 1.0;
    force.m_load[1]     = 4.5;
    force.m_load[2]     = 3.0;
    force.m_factor      = 10.0;

    SG::DataStructure::FEM::NodeData node;//获取力作用的节点信息
    dbManager->get<INodeService> ()->FindById (10, node);
    auto& coordHandler = CoordinateProcessor::GetInstance();

    // Test data
    SG::Algebra::Matrix loadTest;
    LoadCalculator::ForceCalc (coordHandler, force,  node, _OUT loadTest);

    // Target data
    SG::Algebra::Matrix loadTarget(3, 1, {-5.245064E+01, 1.654993E+01, 1.733870E-01});

    // Check
    ASSERT_TRUE (loadTest == loadTarget);
}

TEST_F (ForceInLocalCoordTest, ForceCORD1STest)
{
    // Input
    auto& coordHandler = CoordinateProcessor::GetInstance();

    SG::DataStructure::FEM::FORCEData force;//输入力的信息
    force.m_sId         = 1;
    force.m_coordSysmId = 300;
    force.m_nodeId      = 10;
    force.m_load[0]     = 2.0;
    force.m_load[1]     = 1.0;
    force.m_load[2]     = 3.0;
    force.m_factor      = 50.0;

    SG::DataStructure::FEM::NodeData node;//获取力作用的节点信息
    dbManager->get<INodeService> ()->FindById (10, node);

    // Test data
    SG::Algebra::Matrix loadTest;
    LoadCalculator::ForceCalc (coordHandler, force,  node, _OUT loadTest);

    // Target data
    SG::Algebra::Matrix loadTarget(3, 1, {6.448826E+01, -1.594900E+02, -7.351331E+01});

    // Check
    ASSERT_TRUE (loadTest == loadTarget);
}

TEST_F (ForceInLocalCoordTest, ForceCORD1RTest)
{
    // Input
    auto& coordHandler = CoordinateProcessor::GetInstance();

    SG::DataStructure::FEM::FORCEData force;
    force.m_sId         = 1;
    force.m_coordSysmId = 200;
    force.m_nodeId      = 10;
    force.m_load[0]     = 1.0;
    force.m_load[1]     = 3.0;
    force.m_load[2]     = 2.0;
    force.m_factor      = 10.0;
    SG::DataStructure::FEM::NodeData node;//获取力作用的节点信息
    dbManager->get<INodeService> ()->FindById (10, node);

    // Test data
    SG::Algebra::Matrix loadTest;
    LoadCalculator::ForceCalc (coordHandler, force,  node, _OUT loadTest);

    // Target data
    SG::Algebra::Matrix loadTarget(3, 1, {-1.828874E+01, 2.803058E+01, 1.672747E+01});

    // Check
    ASSERT_TRUE (loadTest == loadTarget);
}

class PLOADTest : public ::testing::Test
{
public:
    static void SetUpTestSuite ()
    {
        // Input
        Cube_OneHexa8Ele model;
        dbManagerPLOAD = model.GetModel();

        // 初始化排序，计算坐标系基矢量
        auto& assembly = AssemblyEigen::GetInstance();
        assembly.Clear();
        
        auto para = dbManagerPLOAD->get<ISubcaseService> () ->FindSubCase (1);
        SG::DataStructure::FEM::Subcase subcase(para);
        assembly.Initialize (dbManagerPLOAD, subcase, {1});

        auto& coordHandler = CoordinateProcessor::GetInstance();
        coordHandler.Initialize (dbManagerPLOAD);
    }
protected:
    static DBServiceFactorySP dbManagerPLOAD;
};

DBServiceFactorySP PLOADTest::dbManagerPLOAD;

TEST_F (PLOADTest, PLoadCalc4PointsTest)
{
    // Input
    SG::DataStructure::FEM::PLOADData force;
    force.m_sId  = 2;
    force.m_P    = 1.0;
    force.m_G[0] = 5;
    force.m_G[1] = 6;
    force.m_G[2] = 7;
    force.m_G[3] = 8;

    // Test data
    SG::Algebra::Matrix loadTest4Points;
    LoadCalculator::PLoadCalc(dbManagerPLOAD->get<INodeService> (), force, loadTest4Points);

    // Target data
    SG::Algebra::Matrix loadTest4PointsTarget(12, 1, {-1.250000E+00, -1.250000E+00, 6.25, -1.250000E+00, -1.250000E+00, 6.25, -1.250000E+00, -1.250000E+00, 6.25, -1.250000E+00, -1.250000E+00, 6.25});

    // Check
    ASSERT_TRUE (loadTest4Points == loadTest4PointsTarget);
}

TEST_F (PLOADTest, PLoadCalc3PointsTest)
{
    // Input
    SG::DataStructure::FEM::PLOADData force;
    force.m_sId  = 2;
    force.m_P    = 1.0;
    force.m_G[0] = 5;
    force.m_G[1] = 6;
    force.m_G[2] = 7;

    // Test data
    SG::Algebra::Matrix loadTest3Points;
    LoadCalculator::PLoadCalc(dbManagerPLOAD->get<INodeService> (), force, loadTest3Points);

    // Target data
    SG::Algebra::Matrix loadTest3PointsTarget(9, 1, {-8.333333E-01, -8.333333E-01, 4.166666666666667, -8.333333E-01, -8.333333E-01, 4.166666666666667, -8.333333E-01, -8.333333E-01, 4.166666666666667});
    // Check
    ASSERT_TRUE (loadTest3Points == loadTest3PointsTarget);
}

TEST_F (PLOADTest, PLoadCalc4PointsNotCoplanarTest)
{
    // Input
    // 输入不同网格数据
    {
        Cube_OneHexa8EleWarpFace model;
        dbManagerPLOAD = model.GetModel();

        // 初始化排序，计算坐标系基矢量
        auto& assembly = AssemblyEigen::GetInstance();
        assembly.Clear();
        
        auto para = dbManagerPLOAD->get<ISubcaseService> () ->FindSubCase (1);
        SG::DataStructure::FEM::Subcase subcase(para);
        assembly.Initialize (dbManagerPLOAD, subcase, {1});

        auto& coordHandler = CoordinateProcessor::GetInstance();
        coordHandler.Initialize (dbManagerPLOAD);
    }

    SG::DataStructure::FEM::PLOADData force;
    force.m_sId  = 2;
    force.m_P    = 1.0;
    force.m_G[0] = 5;
    force.m_G[1] = 6;
    force.m_G[2] = 7;
    force.m_G[3] = 8;
    // Test data
    SG::Algebra::Matrix loadTest4PointsNotCoplanar;
    LoadCalculator::PLoadCalc(dbManagerPLOAD->get<INodeService> (), force, loadTest4PointsNotCoplanar);
    // Target data
    SG::Algebra::Matrix loadTest4PointsNotCoplanarTarget(12, 1, {-2.916667E+00, -2.916667E+00, 6.25, -2.916667E+00, -2.083333E+00, 6.25, -2.083333E+00, -2.083333E+00, 6.25, -2.083333E+00, -2.916667E+00, 6.25});
   
    // Check
    ASSERT_TRUE (loadTest4PointsNotCoplanar == loadTest4PointsNotCoplanarTarget);
}

TEST (PLOAD2Test, PLOAD24PointsCommonCaseTest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD24PointsCommonCase.bdf";
    std::string dbName = "PLOAD24PointsCommonCase";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);
        
    // Input
    auto& assembly = AssemblyEigen::GetInstance();
    assembly.Assembly(DB_SERVICEFACTORY);

    // Test 模拟计算集中力
    LoadCalculator::ComputeStaticLoad (DB_SERVICEFACTORY, {1});
    assembly.Constraint (DB_SERVICEFACTORY, 1);



    SG::DataStructure::FEM::PLOAD2Data pLoad2;
    pLoad2.m_sId  = 1;
    pLoad2.m_P    = 1.0;
    pLoad2.m_eId  = 1; 
    
    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad2Calc (DB_SERVICEFACTORY, pLoad2, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-1.250000E+00, -1.250000E+00, 6.25, -1.250000E+00, -1.250000E+00, 6.25, -1.250000E+00, -1.250000E+00, 6.25, -1.250000E+00, -1.250000E+00, 6.25});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

class PLOAD1Test : public ::testing::Test
{
public:
    static void SetUpTestSuite ()
    {
        // Input
        auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "Pload1_cbar.bdf";
        std::string dbName = "PLOAD1_cbar";
    
        GetModel (fileName, dbName, DB_SERVICEFACTORY);
    
        initialize (DB_SERVICEFACTORY);

    }
protected:
    static DBServiceFactorySP dbManagerPLOAD;
};

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_FXE_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 4;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.088034E+00,1.088034E+00,1.088034E+00,0.0,0.0,0.0,6.666667E-02,6.666667E-02,6.666667E-02,0.0,0.0,0.0});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_FYE_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 5;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-8.048055E-01 ,  1.609611E+00 , -8.048055E-01 , -1.198023E+00  , 0.0 , 1.198023E+00,
    -1.169105E-02  , 2.338210E-02 , -1.169105E-02  , 1.345409E-01 ,  0.0 , -1.345409E-01});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_FZE_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 6;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-1.398336E+00,0.0,1.398336E+00,7.135369E-01,-1.427074E+00,7.135369E-01,-1.587789E-02,0.0,1.587789E-02,-5.581924E-02,1.116385E-01,-5.581924E-02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_FX_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 1;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.945510E+00,-2.894432E-02,-3.203550E-02,-1.545593E-02,1.009094E+00,-9.936376E-01,5.449023E-02,2.894432E-02,3.203550E-02,-1.545593E-02,-7.894032E-02,9.439625E-02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_FY_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 2;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-2.894432E-02,1.942419E+00,-2.894432E-02,-9.781817E-01,0.0,9.781817E-01,2.894432E-02,5.758142E-02,2.894432E-02,1.098522E-01,0.0,-1.098522E-01});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_FZ_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 3;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);

    // Target data
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-3.203550E-02,-2.894432E-02,1.945510E+00,9.936376E-01,-1.009094E+00,1.545593E-02,3.203550E-02,2.894432E-02,5.449023E-02,-9.439625E-02,7.894032E-02,1.545593E-02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_MYE_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 11;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;


    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-2.575832E-02,0.0,2.575832E-02,-6.405645E-01,1.281129E+00,-6.405645E-01,2.575832E-02,0.0,-2.575832E-02,8.165116E-02,-1.633023E-01,8.165116E-02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_MZE_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 12;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;


    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.388312E-02,-2.776624E-02,1.388312E-02,-1.124317E+00,0.0,1.124317E+00,-1.388312E-02,2.776624E-02,-1.388312E-02,1.265971E-01,0.0,-1.265971E-01});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_MXE_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 10;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;


    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {0.0,0.0,0.0,1.088034E+00,1.088034E+00,1.088034E+00,0.0,0.0,0.0,6.666667E-02,6.666667E-02,6.666667E-02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_MX_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 7;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;


    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {6.989443E-04,1.963369E-02,-2.033264E-02,1.684698E+00,1.051579E-01,9.467375E-02,-6.989443E-04,-1.963369E-02,2.033264E-02,-8.436161E-02,1.051579E-01,9.467375E-02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_MY_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 8;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;


    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-2.103158E-02,0.0,2.103158E-02,1.051579E-01,1.674214E+00,1.051579E-01,2.103158E-02,0.0,-2.103158E-02,1.051579E-01,-9.484577E-02,1.051579E-01});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BARTest_LE_MZ_ConcentrationTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 9;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 1.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;


    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {2.033264E-02,-1.963369E-02,-6.989443E-04,9.467375E-02,1.051579E-01,1.684698E+00,-2.033264E-02,1.963369E-02,6.989443E-04,9.467375E-02,1.051579E-01,-8.436161E-02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FXE_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 4;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.054701E+00, 1.054701E+00, 1.054701E+00, 0.0, 0.0, 0.0, 1.000000E-01, 1.000000E-01, 1.000000E-01, 0.0, 0.0, 0.0});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FYE_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 5;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-7.934589E-01, 1.586918E+00, -7.934589E-01, -1.680498E+00, 0.0, 1.680498E+00, -2.303765E-02, 4.607531E-02, -2.303765E-02, 2.503069E-01, 0.0, -2.503069E-01});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FZE_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 6;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-1.380190E+00, 0.0, 1.380190E+00, 9.996308E-01, -1.999262E+00, 9.996308E-01, -3.402338E-02, 0.0, 3.402338E-02, -1.151197E-01, 2.302394E-01, -1.151197E-01});
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MYE_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 11;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-3.732225E-02, 0.0, 3.732225E-02, -5.591746E-01, 1.118349E+00, -5.591746E-01, 3.732225E-02, 0.0, -3.732225E-02, 1.159006E-01, -2.318012E-01, 1.159006E-01});
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MZE_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 12;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {2.011580E-02, -4.023160E-02, 2.011580E-02, -9.900021E-01, 0.0, 9.900021E-01, -2.011580E-02, 4.023160E-02, -2.011580E-02, 1.792625E-01, 0.0, -1.792625E-01});
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FX_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 1;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.908802E+00, -3.892486E-02, -4.308195E-02, -2.078542E-02, 1.413691E+00, -1.392906E+00, 9.119827E-02, 3.892486E-02, 4.308195E-02, -2.078542E-02, -1.628038E-01, 1.835893E-01});
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MY_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 8;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-3.047349E-02, 0.0, 3.047349E-02, 1.523675E-01, 1.522060E+00, 1.523675E-01, 3.047349E-02, 0.0, -3.047349E-02, 1.523675E-01, -1.315298E-01, 1.523675E-01});
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MZ_UniDistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 9;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {2.946076E-02, -2.844803E-02, -1.012728E-03, 1.371765E-01, 1.523675E-01, 1.537251E+00, -2.946076E-02, 2.844803E-02, 1.012728E-03, 1.371765E-01, 1.523675E-01, -1.163389E-01});
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FXE_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 4;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 7.3;
    pLoad1.m_p2     = 116.7;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.515050E+02, 1.515050E+02, 1.515050E+02, 0.0, 0.0, 0.0, 6.436920E+01, 6.436920E+01, 6.436920E+01, 0.0, 0.0, 0.0});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FYE_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 5;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.645;
    pLoad1.m_p1     = 2.894;
    pLoad1.m_x2     = 6.966;
    pLoad1.m_p2     = 933.65;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-7.836007E+02, 1.567201E+03, -7.836007E+02, -4.185458E+03, 0.0, 4.185458E+03, -2.336215E+02, 4.672430E+02, -2.336215E+02, 2.055489E+03, 0.0, -2.055489E+03});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FZE_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 6;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.3;
    pLoad1.m_p1     = 2.4;
    pLoad1.m_x2     = 6.7;
    pLoad1.m_p2     = 113.5;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-1.764064E+02, 0.0, 1.764064E+02, 3.034646E+02, -6.069292E+02, 3.034646E+02, -4.486848E+01, 0.0, 4.486848E+01, -1.309208E+02, 2.618416E+02, -1.309208E+02});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MYE_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 11;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 3.0;
    pLoad1.m_p2     = 5.0;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-1.779307E-01, 0.0, 1.779307E-01, -1.614531E+00, 3.229062E+00, -1.614531E+00, 1.779307E-01, 0.0, -1.779307E-01, 5.361002E-01, -1.072200E+00, 5.361002E-01});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MZE_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 12;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.75;
    pLoad1.m_p1     = 2.84;
    pLoad1.m_x2     = 3.46;
    pLoad1.m_p2     = 5.79;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.232428E-01, -2.464857E-01, 1.232428E-01, -2.554794E+00, 0.0, 2.554794E+00, -1.232428E-01, 2.464857E-01, -1.232428E-01, 1.034586E+00, 0.0, -1.034586E+00});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_FY_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 2;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.36;
    pLoad1.m_p1     = 2.65;
    pLoad1.m_x2     = 3.52;
    pLoad1.m_p2     = 115.79;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-3.449505E+00, 1.142547E+02, -3.449505E+00, -1.374411E+02, 0.0, 1.374411E+02, 3.449505E+00, 1.366054E+01, 3.449505E+00, 3.395595E+01, 0.0, -3.395595E+01});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MY_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 8;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 0.36;
    pLoad1.m_p1     = 13.65;
    pLoad1.m_x2     = 5.52;
    pLoad1.m_p2     = 1035.79;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-8.660475E+01, 0.0, 8.660475E+01, 4.330238E+02, 1.250986E+03, 4.330238E+02, 8.660475E+01, 0.0, -8.660475E+01, 4.330238E+02, -2.755258E+02, 4.330238E+02});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LE_MZ_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 9;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 3.36;
    pLoad1.m_p1     = -115.7;
    pLoad1.m_x2     = 12.36;
    pLoad1.m_p2     = 653.2;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.070404E+02, -1.033609E+02, -3.679567E+00, 4.984066E+02, 5.536001E+02, -3.052799E+01, -1.070404E+02, 1.033609E+02, 3.679567E+00, 4.984066E+02, 5.536001E+02, 3.452647E+02});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_FR_MZ_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 9;
    pLoad1.m_scale  = 2;
    pLoad1.m_x1     = 0.32;
    pLoad1.m_p1     = -115.7;
    pLoad1.m_x2     = 0.89;
    pLoad1.m_p2     = 653.2;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {9.091655E+01, -8.779125E+01, -3.125301E+00, 4.233297E+02, 4.702092E+02, -2.060690E+02, -9.091655E+01, 8.779125E+01, 3.125301E+00, 4.233297E+02, 4.702092E+02, 1.072276E+03});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST_F (PLOAD1Test, PLOAD1BAR_LEPR_FY_DistributionTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 2;
    pLoad1.m_scale  = 3;
    pLoad1.m_x1     = 0.0;
    pLoad1.m_p1     = 2.65;
    pLoad1.m_x2     = 10.0;
    pLoad1.m_p2     = 115.79;

    SG::Algebra::Matrix loadMatrixTest;

    // 计算载荷向量
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-5.733836E+00, 3.109685E+02, -5.733836E+00, -6.092191E+02, 0.0, 6.092191E+02, 5.733836E+00, 1.725608E+02, 5.733836E+00, 4.372041E+02, 0.0, -4.372041E+02});
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

class PLOAD1FreeDofTest : public ::testing::Test
{
public:
    static void SetUpTestSuite ()
    {
        // Input
        auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "Pload1_cbar_freeDof.bdf";
        std::string dbName = "PLOAD1_cbar_freeDof";
    
        GetModel (fileName, dbName, DB_SERVICEFACTORY);
    
        initialize (DB_SERVICEFACTORY);

    }
protected:
    static DBServiceFactorySP dbManagerPLOADFreeDof;
};


// 自由度释放测试
TEST_F (PLOAD1FreeDofTest, PLOAD1BAR_LE_FX_UniDistribution_freeDofTest)
{
    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 2;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 1;
    pLoad1.m_scale  = 1;
    pLoad1.m_x1     = 1.0;
    pLoad1.m_p1     = 2.0;
    pLoad1.m_x2     = 2.0;
    pLoad1.m_p2     = 2.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);

    // 目标结果
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {1.666667E+00,   6.666667E-01,  -3.333333E-01,  -9.133975E+00,   0.0,            9.133975E+00,
                                                     3.333333E-01,  -6.666667E-01,   3.333333E-01,  -8.660254E-01,   1.732051E+00,  -8.660254E-01});

    // 验证结果
    ASSERT_TRUE(loadMatrixTest == loadMatrixTestTarget);
}

// 测试当K为0时
TEST (PLOAD1Test1, PLOAD1_cbar_K0)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD1_cbar_K0.bdf";
    std::string dbName = "PLOAD1_cbar_K0";
    DB_SERVICEFACTORY->ClearDatabase();
    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD1Data pLoad1;
    pLoad1.m_sId    = 1;
    pLoad1.m_eId    = 2;
    pLoad1.m_type   = 5;
    pLoad1.m_scale  = 2;
    pLoad1.m_x1     = 0.0;
    pLoad1.m_p1     = 600.0;

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad1Calc (DB_SERVICEFACTORY, pLoad1, loadMatrixTest, nodeIndexes);
    std::cout << 1.0 <<std::endl;


    // 目标结果
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {3.410605E-13,  6.000000E+02,   0.0,            0.0,            0.0,           -6.821210E-13,
                                                     0.0,  0.0,   0.0,  0.0,   0.0,  0.0});

    // 验证结果
    ASSERT_TRUE(loadMatrixTest == loadMatrixTestTarget);
}

TEST (PLOAD4Test, PLOAD4TriaCommonCaseTest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4TriaCommonCase.bdf";
    std::string dbName = "PLOAD4TriaCommonCase";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 0.5;
    pLoad4.m_P[1] = 1.0;
    pLoad4.m_P[2] = 2.0;
    pLoad4.m_eId  = 1; 
    

    // 计算载荷向量及载荷作用节点的索引
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(9, 1, {1.6666666666666665, 0.83333333333333326, -4.166666666666667,
                                                    1.875, 0.9375, -4.6875,
                                                    2.291666666666667, 1.1458333333333335, -5.7291666666666679});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST (PLOAD4Test, PLOAD4TriaWithNTest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4TriaWithN.bdf";
    std::string dbName = "PLOAD4TriaWithN";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 0.5;
    pLoad4.m_P[1] = 1.0;
    pLoad4.m_P[2] = 2.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_N[0] = 0.0;
    pLoad4.m_N[1] = 0.0;
    pLoad4.m_N[2] = 1.0;
    

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(9, 1, {0.0, 0.0, 4.564355E+00, 0.0, 0.0, 5.134899E+00, 0.0, 0.0, 6.275988E+00});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST (PLOAD4Test, PLOAD4TriaWithTg)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4TriaWithTg.bdf";
    std::string dbName = "PLOAD4TriaWithTg";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 0.5;
    pLoad4.m_P[1] = 1.0;
    pLoad4.m_P[2] = 2.0;
    pLoad4.m_eId  = 1; 
    

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(9, 1, {1.666667E+00, 8.333333E-01, -4.166667E+00 , 1.875000E+00, 9.375000E-01, -4.687500E+00, -4.440892E-16, 6.275988E+00, 0.0});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST (PLOAD4Test, PLOAD4QuadCommonCaseTest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4QuadCommonCase.bdf";
    std::string dbName = "PLOAD4QuadCommonCase";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 0.5;
    pLoad4.m_P[1] = 1.0;
    pLoad4.m_P[2] = 2.0;
    pLoad4.m_P[3] = 3.0;
    pLoad4.m_eId  = 1; 
    

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-2.083333E+02, -2.083333E+02, -2.083333E+02, -2.083333E+02, -2.083333E+02, -2.083333E+02, -2.864583E+02, -2.864583E+02, -2.864583E+02, -3.125000E+02, -3.125000E+02, -3.125000E+02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST (PLOAD4Test, PLOAD4QuadCommonCaseWithNTest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4QuadCommonCaseWithN.bdf";
    std::string dbName = "PLOAD4QuadCommonCaseWithN";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 0.5;
    pLoad4.m_P[1] = 0.5;
    pLoad4.m_P[2] = 0.5;
    pLoad4.m_P[3] = 0.5;
    pLoad4.m_eId  = 1;
    pLoad4.m_N[0] = 0.0;
    pLoad4.m_N[1] = 0.0;
    pLoad4.m_N[2] = 1.0;
    

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {0, 0, 1.353165E+02, 0, 0, 1.353165E+02, 0, 0, 1.353165E+02, 0, 0, 1.353165E+02});

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST (PLOAD4Test, PLOAD4QuadCommonCaseWithTgTest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4QuadCommonCaseWithTg.bdf";
    std::string dbName = "PLOAD4QuadCommonCaseWithTg";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 0.5;
    pLoad4.m_P[1] = 1.0;
    pLoad4.m_P[2] = 2.0;
    pLoad4.m_P[3] = 3.0;
    pLoad4.m_eId  = 1; 
    

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-2.083333E+02, -2.083333E+02, -2.083333E+02, -2.083333E+02, -2.083333E+02, -2.083333E+02, -2.864583E+02, -2.864583E+02, -2.864583E+02, 1.421085E-14, 5.412659E+02, -5.684342E-14});
    
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
}

TEST (PLOAD4Test, PLOAD4_CHEXA8CommonCaseTest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4_CHEXA8CommonCase.bdf";
    std::string dbName = "PLOAD4_CHEXA8CommonCase";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 1000.0;
    pLoad4.m_P[1] = 2000.0;
    pLoad4.m_P[2] = 3000.0;
    pLoad4.m_P[3] = 4000.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_G1   = 15; 
    pLoad4.m_G34   = 25; 


    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-1.319444E+06, 2.638889E+05, -2.638889E+05,
                                                     -1.805556E+06, 3.611111E+05, -3.611111E+05,
                                                     -1.736111E+06, 3.472222E+05, -3.472222E+05,
                                                     -1.388889E+06, 2.777778E+05, -2.777778E+05});
    std::vector<std::size_t> nodeIndexesTarget{5, 4, 7, 6};
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
    ASSERT_TRUE (nodeIndexes == nodeIndexesTarget);
}

class PLOAD4CPYRAM5Test : public ::testing::Test
{
public:
    static void SetUpTestSuite ()
    {
        OnePyram5Ele model;
        DB_SERVICEFACTORY = model.GetModel();
        initialize (DB_SERVICEFACTORY);
    }
protected:
    static DBServiceFactorySP DB_SERVICEFACTORY;
};

TEST (PLOAD4CPYRAM5Test, PLOAD4CPyram5Quad4CaseTest)
{
    // GTEST_SKIP ();
    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 1000.0;
    pLoad4.m_P[1] = 2000.0;
    pLoad4.m_P[2] = 3000.0;
    pLoad4.m_P[3] = 4000.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_G1   = 1; 
    pLoad4.m_G34  = 5; 

    OnePyram5Ele model;
    DB_SERVICEFACTORY = model.GetModel();
    initialize (DB_SERVICEFACTORY);

    // Test data
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    // Target data
    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {-9.222222E+03, 9.222222E+03, 4.611111E+04,
                                                     -1.305556E+04, 1.305556E+04, 6.527778E+04,
                                                     -1.300000E+04, 1.300000E+04, 6.500000E+04,
                                                     -1.005556E+04, 1.005556E+04, 5.027778E+04});
    std::vector<std::size_t> nodeIndexesTarget{0, 1, 3, 2};

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
    ASSERT_TRUE (nodeIndexes == nodeIndexesTarget);
}

TEST (PLOAD4CPYRAM5Test, PLOAD4CPyram5TriaCase1Test)
{
    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 1000.0;
    pLoad4.m_P[1] = 2000.0;
    pLoad4.m_P[2] = 3000.0;
    pLoad4.m_P[3] = 0.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_G1   = 1; 
    pLoad4.m_G34   = 3; 

    OnePyram5Ele model;
    DB_SERVICEFACTORY = model.GetModel();
    initialize (DB_SERVICEFACTORY);

    // Test data
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(9, 1, {2.625000E+04, 2.916667E+03, 0.0,
                                                    3.375000E+04, 3.750000E+03, 0.0,
                                                    3.000000E+04, 3.333333E+03, 0.0});
    std::vector<std::size_t> nodeIndexesTarget{0, 2, 4};

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
    ASSERT_TRUE (nodeIndexes == nodeIndexesTarget);
}

TEST (PLOAD4CPYRAM5Test, PLOAD4CPyram5TriaCase2Test)
{
    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 1000.0;
    pLoad4.m_P[1] = 2000.0;
    pLoad4.m_P[2] = 3000.0;
    pLoad4.m_P[3] = 0.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_G1   = 2; 
    pLoad4.m_G34   = 1; 

    OnePyram5Ele model;
    DB_SERVICEFACTORY = model.GetModel();
    initialize (DB_SERVICEFACTORY);

    // Test data
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(9, 1, {7.583333E+03, 2.158333E+04, -2.333333E+04,
                                                    9.750000E+03, 2.775000E+04, -3.000000E+04,
                                                    8.666667E+03, 2.466667E+04, -2.666667E+04});
    std::vector<std::size_t> nodeIndexesTarget{1, 0, 4};

    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
    ASSERT_TRUE (nodeIndexes == nodeIndexesTarget);
}

class PLOAD4CPENTA6Test : public ::testing::Test
{
public:
    static void SetUpTestSuite ()
    {
        auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4_CPENTA6CommonCase.bdf";
        std::string dbName = "PLOAD4_CPENTA6CommonCase";
    
        GetModel (fileName, dbName, DB_SERVICEFACTORY);
    
        initialize (DB_SERVICEFACTORY);
    }
protected:
    // static DBServiceFactorySP DB_SERVICEFACTORY;
};

TEST_F (PLOAD4CPENTA6Test, 4PointsTest)
{
    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 1000.0;
    pLoad4.m_P[1] = 2000.0;
    pLoad4.m_P[2] = 3000.0;
    pLoad4.m_P[3] = 4000.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_G1   = 3; 
    pLoad4.m_G34   = 4; 


    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(12, 1, {
        -2.638889E+04, -2.638889E+04, 1.599227E-12, 
        -3.611111E+04, -3.611111E+04, 4.285116E-13,
        -3.472222E+04, -3.472222E+04, 4.736638E-13, 
        -2.777778E+04, -2.777778E+04, 1.767737E-12});
    std::vector<std::size_t> nodeIndexesTarget{2, 0, 3, 5};
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
    ASSERT_TRUE (nodeIndexes == nodeIndexesTarget);
}

TEST_F (PLOAD4CPENTA6Test, 3PointsTest)
{
    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 1000.0;
    pLoad4.m_P[1] = 2000.0;
    pLoad4.m_P[2] = 3000.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_G1   = 4; 
    // pLoad4.m_G34  = 0; 

    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(9, 1, {
        0.0, 0.0, -1.458333E+04, 
        0.0, 0.0, -1.875000E+04, 
        0.0, 0.0, -1.666667E+04}); 
    std::vector<std::size_t> nodeIndexesTarget{3, 4, 5};
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
    ASSERT_TRUE (nodeIndexes == nodeIndexesTarget);
}

TEST (PLOAD4Test, PLOAD4_CTENTRATest)
{
    auto fileName = SG::Utility::FileSystem::getTestDataPath("SGFem/AnalysisProcess/") + "PLOAD4CTENTRACommonCase.bdf";
    std::string dbName = "PLOAD4CTENTRACommonCase";

    GetModel (fileName, dbName, DB_SERVICEFACTORY);

    initialize (DB_SERVICEFACTORY);

    SG::DataStructure::FEM::PLOAD4Data pLoad4;
    pLoad4.m_sId  = 1;
    pLoad4.m_P[0] = 1000.0;
    pLoad4.m_P[1] = 2000.0;
    pLoad4.m_P[2] = 3000.0;
    pLoad4.m_eId  = 1; 
    pLoad4.m_G1   = 1; 
    pLoad4.m_G34  = 5; 


    // 计算载荷向量
    SG::Algebra::Matrix loadMatrixTest;
    std::vector<std::size_t> nodeIndexes;
    LoadCalculator::PLoad4Calc (DB_SERVICEFACTORY, pLoad4, loadMatrixTest, nodeIndexes);

    SG::Algebra::Matrix loadMatrixTestTarget(9, 1, {
                                                    5.833333E+03, 2.975000E+04, -2.916667E+04,
                                                    7.500000E+03, 3.825000E+04, -3.750000E+04,
                                                    6.666667E+03, 3.400000E+04, -3.333333E+04});
    std::vector<std::size_t> nodeIndexesTarget{0, 3, 1};
    // Checks
    ASSERT_TRUE (loadMatrixTest == loadMatrixTestTarget);
    ASSERT_TRUE (nodeIndexes == nodeIndexesTarget);
}